import request from './config'
import {
  getQuery
} from '@/utils'

// 分页获取菜单列表
export function menuPage(data) {
  const query = getQuery(data)
  return request({
    url: `/menu/page${query}`,
    method: 'get',
  })
}

// 不分页获取菜单列表
export function menuList(data) {
  const query = getQuery(data)
  return request({
    url: `/menu/list${query}`,
    method: 'get',
  })
}

// 新增菜单
export function menuSave(data) {
  return request({
    url: `/menu/save`,
    method: 'post',
    data
  })
}

// 编辑菜单
export function menuUpdate(data) {
  return request({
    url: `/menu/update/by/${data.id}`,
    method: 'post',
    data
  })
}

// 删除菜单
export function menuDelete(data) {
  return request({
    url: `/menu/delete`,
    method: 'post',
    data
  })
}

// 根据id获取菜单详情
export function menuDetail(data) {
  return request({
    url: `/menu/detail/${data.id}`,
    method: 'get',
    data
  })
}

// 分页获取社区列表
export function communityPage(data) {
  const query = getQuery(data)
  return request({
    url: `/community/page${query}`,
    method: 'get',
  })
}

// 新增社区
export function communitySave(data) {
  return request({
    url: `/community/save`,
    method: 'post',
    data
  })
}

// 编辑社区
export function communityUpdate(data) {
  return request({
    url: `/community/update/by/${data.id}`,
    method: 'post',
    data
  })
}

// 删除社区
export function communityDelete(data) {
  return request({
    url: `/community/delete`,
    method: 'post',
    data
  })
}

// 获取社区详情
export function communityDetail(data) {
  return request({
    url: `/community/detail/${data.id}`,
    method: 'get',
    data
  })
}

// 给指定社区绑定菜单(支持批量菜单)
export function communityMenuSave(communityId, data) {
  return request({
    url: `/community/menu/save/${communityId}`,
    method: 'post',
    data
  })
}

// 根据社区id获取社区下所有菜单(不分页)
export function communityAndMenuList(data) {
  const query = getQuery(data)
  return request({
    url: `/community/andMenu/list${query}`,
    method: 'get',
    data
  })
}

// 根据社区id获取社区下所有菜单(分页)
export function communityAndMenuPage(data) {
  const query = getQuery(data)
  return request({
    url: `/community/andMenu/page${query}`,
    method: 'get',
    data
  })
}

// 分页查询订单列表
export function orderPage(data) {
  const query = getQuery(data)
  return request({
    url: `/order/page${query}`,
    method: 'get',
    data
  })
}

export default {
  menuPage,
  menuList,
  menuSave,
  menuDelete,
  menuDetail,
  menuUpdate,
  communityPage,
  communitySave,
  communityUpdate,
  communityDelete,
  communityDetail,
  orderPage,
  communityAndMenuPage,
  communityAndMenuList,
  communityMenuSave,
}
